<#include "/able/_inc/_head.html"/>
<#include "/able/_inc/_layout.html"/>

<!DOCTYPE HTML>
<!--[if IE 8]><html class="ie8" lang="en"><![endif]-->
<!--[if IE 9]><html class="ie9" lang="en"><![endif]-->
<!--[if !IE]><!-->
<html lang="${lang}">

<head>
    <@head />
</head>
<body>
<@layout>
<div class="wrap-content" id="container">
<!-- start: PAGE TITLE -->
<section id="page-title" >
    <div class="row">
        <div class="col-sm-8">
            <a href="${ctx_admin}/role" class="btn btn-o btn-primary" style="border-radius: 50px;padding: 5px 8px"><i class="fa fa-reply"></i></a>
            <label>角色 - 添加角色</label>
        </div>

    </div>
</section>
<!-- end: PAGE TITLE -->
<!-- start: BASIC TABLE -->

<div class="container-fluid container-fullw bg-white">

    <div class="row">
        <div class="col-md-12">
            <!--<h5 class="over-title margin-bottom-15">Basic <span class="text-bold">Table</span></h5>-->
            <!--<p>-->
            <!--For basic styling&mdash;light padding and only horizontal dividers&mdash;add the base class <code>.table</code> to any <code>&lt;table&gt;</code>. It may seem super redundant, but given the widespread use of tables for other plugins like calendars and date pickers, we've opted to isolate our custom table styles.-->
            <!--</p>-->
            <div class="alert alert-info">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
                <div><i class="fa fa-question-circle"></i>操作提示</div>
                <ul>
                    <li>标识“<em>*</em>”的选项为必填项，其余为选填项。</li>
                    <li>上传图片时请注意图片尺寸问题。</li>
                </ul>
            </div>

            <div class="col-lg-2 col-md-12"></div>
            <div class="col-lg-8 col-md-12">
                <form id="form" role="form" class="form-horizontal" method="post" action="${ctx_admin}/<#if model?exists>/role/update<#else>/role/add</#if>">

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="roleName">
                            角色名称：<span class="symbol required" aria-required="true"></span>
                        </label>
                        <div class="col-sm-7">
                            <input type="hidden" id="roleId" name="roleId" value="${model.roleId}">
                            <input type="text" id="roleName" name="roleName" placeholder="角色名称"  class="form-control required"  value="${model.roleName}" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="roleCode">
                            角色code：<span class="symbol required" aria-required="true"></span>
                        </label>
                        <div class="col-sm-7">
                            <input type="text" id="roleCode" name="roleCode" placeholder="角色code"  class="form-control required"  value="${model.roleCode}" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="roleType">
                            角色类型：<span class="symbol required" aria-required="true"></span>
                        </label>
                        <div class="col-sm-7">
                            <select id="roleType" name="roleType" class="form-control required">
                                <option value="1">系统</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label" for="roleLevel">
                            角色级别：<span class="symbol required" aria-required="true"></span>
                        </label>
                        <div class="col-sm-7">
                            <input id="roleLevel" type="text" name="roleLevel" placeholder="角色级别" class="form-control required" value="${model.roleLevel}" >
                        </div>
                    </div>

                    <div class="form-group margin-bottom-0">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button class="btn  btn-primary" type="submit">
                                确定
                            </button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-lg-2 col-md-12"></div>
        </div>
    </div>
</div>

    </@layout>
<!-- The main application script -->

<script type="text/javascript">


    var FormValidator = function () {
        "use strict";
        // function to initiate Validation Sample 2
        var runValidator2 = function () {
            var form2 = $('#form');
            var errorHandler2 = $('.errorHandler', form2);
            var successHandler2 = $('.successHandler', form2);

            form2.validate({
                errorElement: "span", // contain the error msg in a small tag
                errorClass: 'help-block',
                errorPlacement: function (error, element) { // render error placement for each input type
                    if (element.attr("type") == "radio" || element.attr("type") == "checkbox") { // for chosen elements, need to insert the error after the chosen container
                        error.insertAfter($(element).closest('.form-group').children('div').children().last());
                    } else {
                        error.insertAfter(element);
                        // for other inputs, just perform default behavior
                    }
                },
                ignore: "",
                rules: {
                },
                messages: {

                },
                invalidHandler: function (event, validator) { //display error alert on form submit
                    successHandler2.hide();
                    errorHandler2.show();
                },
                highlight: function (element) {
                    $(element).closest('.help-block').removeClass('valid');
                    // display OK icon
                    $(element).closest('.form-group').removeClass('has-success').addClass('has-error').find('.symbol').removeClass('ok').addClass('required');
                    // add the Bootstrap error class to the control group
                },
                unhighlight: function (element) { // revert the change done by hightlight
                    $(element).closest('.form-group').removeClass('has-error');
                    // set error class to the control group
                },
                success: function (label, element) {
                    label.addClass('help-block valid');
                    // mark the current input as valid and display OK icon
                    $(element).closest('.form-group').removeClass('has-error').addClass('has-success').find('.symbol').removeClass('required').addClass('ok');
                },
                submitHandler: function (form) {
                    successHandler2.show();
                    errorHandler2.hide();
                    // submit form

                    $.ajax({
                        type:'post',
                        url:url,
                        async:false, //同步方法，如果用异步的话，flag永远为1
                        dataType:'json',
                        data:$(form).serialize(),
                        success: function(res){
                            if(res.success){
                                layer.msg(res.message, {
                                    icon: 1,
                                    time: 2000, ///2秒关闭（如果不配置，默认是3秒）
                                }, function(){
                                    location.href= global.adminPath + "/role";
                                });

                            }else{
                                layer.msg(res.message, {icon: 1});
                            }
                        }
                    });
                }
            });
        };
        return {
            //main function to initiate template pages
            init: function () {
                runValidator2();
            }
        };
    }();

    jQuery(document).ready(function() {
        FormValidator.init();
    });
</script>